﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using upcdew_20111_group2b.CapaNegocio;
using upcdew_20111_group2b.CapaDominio;

namespace upcdew_20111_group2b.Controllers
{
    public class Area_ComunController : Controller
    {
        //
        // GET: /Area_Comun/
        public AdminCondominio AdminCondominio { get; set; }

        public ActionResult Index()
        {
            ICollection<Area_Comun> modelo = AdminCondominio.ListarTodosLosArea_Comun();
            return View(modelo);
        }

        //
        // GET: /Area_Comun/Details/5

        public ActionResult Details(String codareacomun)
        {
            Area_Comun modelo = AdminCondominio.ObtenerArea_Comun(codareacomun);
            return View(modelo);
        }

        //
        // GET: /Area_Comun/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Area_Comun/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Area_Comun area_comunCrear = new Area_Comun();
                    area_comunCrear.CodAreaComun = (String)collection["CodAreaComun"];
                    area_comunCrear.Tex_Tipo = (String)collection["Tex_Tipo"];
                    area_comunCrear.Tex_Ubicacion = (String)collection["Tex_Ubicacion"];
                    area_comunCrear.Num_Capacidad = Int32.Parse(collection["Num_Capacidad"]);
                    area_comunCrear.Tex_Estado = (String)collection["Tex_Estado"];                    
                    AdminCondominio.CrearArea_Comun(area_comunCrear);
                    return RedirectToAction("Index");
                }
                else
                {
                    return View();
                }                                
            }
            catch (Exception e)
            {
                ModelState.AddModelError(String.Empty, "Error al crear el area comun: " + e.Message);
                return View();
            }
        }
        
        //
        // GET: /Area_Comun/Edit/5
 
        public ActionResult Edit(String codareacomun)
        {
            Area_Comun modelo = AdminCondominio.ObtenerArea_Comun(codareacomun);
            return View(modelo);
        }

        //
        // POST: /Area_Comun/Edit/5

        [HttpPost]
        public ActionResult Edit(String codareacomun, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                Area_Comun area_comunModificar = AdminCondominio.ObtenerArea_Comun(codareacomun);                
                area_comunModificar.Tex_Tipo = (String)collection["Tex_Tipo"];
                area_comunModificar.Tex_Ubicacion = (String)collection["Tex_Ubicacion"];
                area_comunModificar.Num_Capacidad = Int32.Parse(collection["Num_Capacidad"]);
                area_comunModificar.Tex_Estado = (String)collection["Tex_Estado"];                
                AdminCondominio.ModificarArea_Comun(area_comunModificar);
                return RedirectToAction("Index");                
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Area_Comun/Delete/5
 
        public ActionResult Delete(String codareacomun)
        {
            Area_Comun modelo = AdminCondominio.ObtenerArea_Comun(codareacomun);
            return View(modelo);
        }

        //
        // POST: /Area_Comun/Delete/5

        [HttpPost]
        public ActionResult Delete(String codareacomun, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                Area_Comun area_comunEliminar = AdminCondominio.ObtenerArea_Comun(codareacomun);
                AdminCondominio.EliminarArea_Comun(area_comunEliminar);
                return RedirectToAction("Index");                
            }
            catch
            {
                return View();
            }
        }
    }
}
